<?

/*	StatsBasic OBJECT
*	Methods:
*	output
*
*
*					*/


class StatsBasic extends MOD {

	public function output() {
		
		if( $this->action )
			$result = $this->{ "filter_" . $this->action }();

		if( $result )
			$this->addclass( $this->action );
			
		return $this->parse( $result ) . $this->render_js();
		
	}
	
	function filter_count() {
		global $DB, $Object;
		
		if( !$Object || $Object->type != $this->vars->type )
			$Object = new OBJECT( $this->vars->type, (int) ($this->vars->id)? $this->vars->id : $_GET['id'] );
		
		
		foreach( $this->vars->values as $value )
			$stats[ $value ] += $Object->get( $value );
			
		
		$togo = $stats[ $this->vars->values[ 0 ]] - $stats[ $this->vars->values[ 1 ]];
		$proc = round (( $stats[ $this->vars->values[ 1 ]] / $stats[ $this->vars->values[ 0 ]] ) * 100 );
		
		
		return "<div class='cont'><div class='bar' style='width:$proc%'></div></div><span class='amount'>&euro; $togo to go...</span>";
		
	}
	
	
	function filter_overall() {
		global $DB;
		
		$objs = $DB->filter_objects( $this->vars->type, $this->vars->condt );
		
		foreach( $this->vars->values as $value )
			foreach( $objs as $obj ) $stats[ $value ] += $obj->get( $value );
			
		foreach( $stats as $key => $stat ) $result[] = $this->render_li( $stat, $key );
			
			
		return "<ul>" . implode( "\n", $result ) . "</ul>";
		
	}
	
	function filter_allstat() {
		global $DB;
		
		$objs = $DB->filter_objects( $this->vars->type, $this->vars->condt );
		
		foreach( $this->vars->values as $value )
			foreach( $objs as $obj ) $stats[ $value ] += $obj->get( $value );
			
		
		$togo = $stats[ $this->vars->values[ 0 ]] - $stats[ $this->vars->values[ 1 ]];
		$proc = round (( $stats[ $this->vars->values[ 1 ]] / $stats[ $this->vars->values[ 0 ]] ) * 100 );
		
		
		return "<div class='cont'><div class='bar' style='width:$proc%'></div></div><span class='amount'>&euro; $togo to go...</span>";
		
	}



	function render_li( $content, $class = "" ) {
		
		if( $class ) $class = " class='$class'";
		return "<li$class>$content</li>";
	}
} 

?>